package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsAd;
import com.qf.pojo.DtsArticle;
import com.qf.service.DtsAdService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/ad")
public class DtsAdminAdController {
    @Autowired
    DtsAdService adService;


    @RequestMapping("/delete")
    public Object delete(@RequestBody DtsAd dtsAd){
        adService.delete(dtsAd);
        return ResponseUtil.ok();
    }

    @RequestMapping("/update")
    public Object update(@RequestBody DtsAd dtsAd){
        adService.update(dtsAd);
        return ResponseUtil.ok();
    }

    @RequestMapping("/create")
    public Object create(@RequestBody DtsAd dtsAd){
        DtsAd ad=adService.add(dtsAd);
       return ResponseUtil.ok(ad);
    }

    @RequestMapping("/list")
    public Object list(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(name = "limit",required = false,defaultValue = "20")Integer limit,
                       String sort, String order, String name,String content){
        IPage<DtsAd> iPage =adService.findByPage(page,limit,sort,order,name,content);
        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
